package com.fruit.controller.app.login;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.user.SysUser;
import com.fruit.service.user.SysUserManager;
import com.fruit.util.ResultInfo;
import com.fruit.util.ResultUtil;



@Controller
@RequestMapping(value = "/app/")
public class LoginController extends BaseController {

	@Autowired
	private SysUserManager sysUserService;
	
	@RequestMapping(value = "/login_login")
	@ResponseBody
	public Map<String, Object> login(SysUser sysUser, HttpSession session) throws Exception {
		Map<String, Object> resMap = new HashMap<String, Object>();
		try{
		//判断参数
		String userName = sysUser.getUserName();
		if(StringUtils.length(userName)<1 || StringUtils.length(userName)>32){
			resMap.put("result", ResultUtil.initResult(ResultInfo.ERROR, "user_error", "用户名格式错误!"));
			return resMap;
		}
		String password = sysUser.getPassword();
		if(StringUtils.length(password)<1 || StringUtils.length(password)>32){
			resMap.put("result", ResultUtil.initResult(ResultInfo.ERROR, "password_error", "密码格式错误!"));
			return resMap;
		}
		
		resMap = sysUserService.saveLogin(sysUser);
		}catch(Exception e){
			e.printStackTrace();
			resMap.put("result", ResultUtil.initResult(ResultInfo.ERROR, "exception", "系统异常!"));
			return resMap;
		}
	
		return resMap;
	}
	
}
